Setting Up VS Code for Flutter – Detailed Notes
Visual Studio Code (VS Code) is a lightweight, powerful, and customizable code editor that can be used to develop Flutter applications. With the Flutter and Dart extensions installed, VS Code provides features such as code completion, syntax highlighting, debugging, widget assistance, hot reload, device selection, and Flutter DevTools.
Flutter officially supports VS Code as one of the editors for Flutter development. The Flutter extension also installs the Dart extension, providing the language support required for Dart and Flutter development.
For structured Flutter training and additional learning resources, visit JustAcademy Flutter Training. You can also register for a course demo through JustAcademy Course Demo Registration.
1. What is VS Code?
Visual Studio Code, commonly called VS Code, is a source-code editor developed by Microsoft. It supports multiple programming languages and can be extended using extensions.
For Flutter development, VS Code works together with the Flutter SDK, Dart SDK, Flutter extension, and Dart extension to provide a complete development environment.
Important VS Code Features for Flutter
- Flutter and Dart syntax highlighting
- Code completion and IntelliSense
- Widget suggestions
- Quick fixes and code assists
- Debugging support
- Breakpoints
- Hot reload
- Hot restart
- Device selection
- Flutter project creation
- Flutter Doctor integration
- Flutter DevTools integration
- Integrated terminal
- Git and source-control integration
2. Requirements Before Setting Up VS Code
Before configuring VS Code for Flutter development, make sure the required development tools are available on your computer.
| Requirement |
Purpose |
| Visual Studio Code |
Used for writing, running, and debugging Flutter code. |
| Flutter SDK |
Provides the Flutter framework and Flutter command-line tools. |
| Dart SDK |
Provides the Dart programming language used by Flutter. |
| Git |
Used by Flutter tooling and commonly used for source-code management. |
| Flutter Extension |
Adds Flutter-specific development features to VS Code. |
| Dart Extension |
Adds Dart language support to VS Code. |
| Target Device |
Used to run and test the Flutter application. |
3. Download and Install VS Code
First, install Visual Studio Code on your computer.
Installation Steps
- Download Visual Studio Code for your operating system.
- Run the VS Code installer.
- Accept the license agreement.
- Select the installation location.
- Choose the required installation options.
- Click Install.
- Launch Visual Studio Code after installation.
After opening VS Code, you should see the editor interface containing the Activity Bar, Explorer, Search, Source Control, Run and Debug, Extensions, editor area, terminal, and status bar.
4. Install Flutter Extension
The Flutter extension adds Flutter-specific development capabilities to VS Code. Installing the Flutter extension also installs the Dart extension.
Method 1: Using the Extensions Panel
- Open VS Code.
- Click the Extensions icon from the Activity Bar.
- Search for Flutter.
- Find the official Flutter extension.
- Click Install.
- Allow VS Code to complete the installation.
Method 2: Using Command Palette
- Open VS Code.
- Press Ctrl + Shift + P on Windows/Linux or Cmd + Shift + P on macOS.
- Type Extensions: Install Extensions.
- Search for Flutter.
- Install the Flutter extension.
Once the Flutter extension is installed, Dart support should also be available.
5. Install Flutter SDK Through VS Code
Modern Flutter tooling allows developers to use VS Code to download and configure the Flutter SDK.
Step-by-Step Process
- Open VS Code.
- Open the Command Palette using Ctrl + Shift + P.
- Type Flutter.
- Select Flutter: New Project.
- If VS Code asks for the Flutter SDK location, select Download SDK.
- Select the folder where you want to install Flutter.
- Click Clone Flutter.
- Wait while VS Code downloads the Flutter SDK.
- After installation, choose Add SDK to PATH when prompted.
- Restart VS Code and reopen terminal windows.
Adding the Flutter SDK's bin directory to the system PATH allows the flutter and dart commands to be used from terminals and development tools.
6. Verify Flutter Installation
After installing Flutter, verify that the Flutter SDK is correctly configured.
Using Terminal
flutter doctor
For more detailed diagnostic information, use:
flutter doctor -v
Example
PS C:\Users\User> flutter doctor
Doctor summary:
[✓] Flutter
[✓] Android toolchain
[✓] Chrome
[✓] Visual Studio
[✓] Connected device
[✓] Network resources
The exact output depends on the operating system and development platforms configured on your computer.
7. Understanding the Flutter Extension
The Flutter extension connects VS Code with the Flutter SDK and provides Flutter-specific commands and development tools.
Major Features
- Create new Flutter projects.
- Run Flutter applications.
- Debug Flutter applications.
- Perform hot reload.
- Perform hot restart.
- Select connected devices.
- Analyze Flutter code.
- Show warnings and errors.
- Open Flutter DevTools.
- Use widget assists and quick fixes.
8. Creating Your First Flutter Project in VS Code
After configuring VS Code, you can create a Flutter project directly from the editor.
Step 1: Open Command Palette
Ctrl + Shift + P
On macOS:
Cmd + Shift + P
Step 2: Select Flutter Project
- Type Flutter: New Project.
- Select the command.
- Choose the Application template.
- Select the parent folder where the project should be created.
- Enter a project name.
- Wait for Flutter to initialize the project.
Example Project Name
my_first_flutter_app
Flutter project names normally follow the lowercase_with_underscores naming convention.
9. Flutter Project Structure in VS Code
A newly created Flutter project contains several folders and files.
my_first_flutter_app/
│
├── android/
├── ios/
├── lib/
│ └── main.dart
├── test/
├── web/
├── windows/
├── macos/
├── linux/
├── pubspec.yaml
├── pubspec.lock
└── README.md
Important Files and Folders
| File/Folder |
Purpose |
| lib/ |
Main location for Dart and Flutter application code. |
| lib/main.dart |
Common entry point for a Flutter application. |
| pubspec.yaml |
Contains project metadata, dependencies, assets, and configuration. |
| android/ |
Android-specific project configuration. |
| ios/ |
iOS-specific project configuration. |
| web/ |
Web-specific Flutter configuration. |
| test/ |
Location for automated tests. |
10. Understanding main.dart
The main.dart file commonly contains the entry point of a Flutter application.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('My Flutter App'),
),
body: const Center(
child: Text('Hello Flutter!'),
),
),
);
}
}
Important Concepts
import imports Flutter libraries.
main() is the Dart entry point.
runApp() starts the Flutter application.
MaterialApp provides Material Design application structure.
Scaffold provides common screen structure.
AppBar creates the application bar.
Center centers its child.
Text displays text.
11. Opening an Existing Flutter Project
Existing Flutter projects can be opened directly in VS Code.
- Open VS Code.
- Select File > Open Folder.
- Select the Flutter project root folder.
- Make sure the selected folder contains
pubspec.yaml.
- Wait for VS Code to analyze the project.
If the Flutter project is correctly detected, Flutter-specific information such as the Flutter SDK version and available devices can appear in the VS Code status bar.
12. Selecting a Flutter Device
Flutter applications need a target device to run. Depending on your setup, the target can be a browser, Android emulator, physical Android device, iOS simulator, or another supported platform.
Common Target Devices
- Chrome
- Edge
- Android Emulator
- Physical Android Device
- iOS Simulator on macOS
- Windows
- macOS
- Linux
Selecting a Device
- Open a Flutter project in VS Code.
- Look at the VS Code status bar.
- Click the device name or No Devices.
- Select the required target device.
13. Running a Flutter Application
Method 1: Run Using F5
Press:
F5
This starts the application in debugging mode.
Method 2: Run Without Debugging
Use:
Run > Start Without Debugging
The application runs without starting a normal breakpoint-based debugging session.
Method 3: Run from Terminal
flutter run
14. Hot Reload
Hot reload is one of Flutter's most useful development features. It allows developers to quickly see many code and UI changes without restarting the entire application.
Example
Suppose the application initially contains:
Text(
'Hello Flutter!',
)
Change it to:
Text(
'Welcome to Flutter!',
)
Save the file and perform a hot reload. The updated text can appear in the running application without rebuilding the entire application from scratch.
Common Hot Reload Shortcut
Ctrl + F5
Depending on the VS Code configuration and Flutter workflow, hot reload can also be triggered through the Flutter debug controls or Command Palette.
15. Hot Restart
Hot restart restarts the Flutter application and resets the current application state. It is useful when changes require more than a simple hot reload.
Hot Reload vs Hot Restart
| Feature |
Hot Reload |
Hot Restart |
| Speed |
Very fast |
Usually slower than hot reload |
| Application State |
Generally preserves current state |
Resets application state |
| Purpose |
Quick UI/code updates |
Restart application state |
16. Debugging Flutter Applications in VS Code
VS Code provides integrated debugging tools for Flutter applications.
Start Debugging
F5
Debugging Features
- Breakpoints
- Step Over
- Step Into
- Step Out
- Continue execution
- Variable inspection
- Call stack inspection
- Debug Console
- Exception and error information
17. Setting Breakpoints
A breakpoint pauses program execution at a specific line so that developers can inspect the application's behavior.
Example
void calculateTotal() {
int price = 100;
int quantity = 2;
int total = price * quantity;
print(total);
}
You can click next to the line containing int total = price * quantity; to create a breakpoint.
When execution reaches that line during debugging, VS Code can pause execution and allow you to inspect variables.
18. IntelliSense and Code Completion
VS Code provides intelligent code completion for Dart and Flutter. This helps developers write code faster and reduces typing errors.
Example
Container(
child: Text(
'Hello',
),
)
When you type Flutter widgets and properties, VS Code can provide suggestions for available classes, methods, parameters, and properties.
19. Quick Fixes and Code Assists
Flutter development in VS Code provides code assists and quick fixes that can help developers modify or correct code.
Place the cursor on a relevant piece of code and press:
Ctrl + .
Common assists include wrapping a widget with another widget, converting code structures, importing missing libraries, and applying suggested corrections.
20. Flutter DevTools in VS Code
Flutter DevTools is a collection of debugging and performance tools for Flutter and Dart applications. It can be launched during a debugging session from VS Code.
DevTools Can Help With
- Widget inspection
- Layout debugging
- Performance analysis
- Memory analysis
- Network inspection
- Application debugging
Opening DevTools
- Open the Flutter project.
- Start a debug session.
- Open the VS Code Command Palette.
- Search for DevTools commands.
- Select the required DevTools feature.
21. Integrated Terminal in VS Code
VS Code includes an integrated terminal, allowing developers to execute Flutter and Dart commands without opening a separate terminal application.
Useful Flutter Commands
flutter doctor
flutter doctor -v
flutter --version
flutter devices
flutter emulators
flutter pub get
flutter clean
flutter run
flutter analyze
flutter test
Example
flutter pub get
This command retrieves the dependencies specified in the project's pubspec.yaml file.
22. Understanding pubspec.yaml
The pubspec.yaml file is one of the most important files in a Flutter project. It contains project metadata, dependencies, assets, and other configuration.
Example
name: my_first_flutter_app
description: A Flutter learning application.
environment:
sdk: '>=3.0.0 <4.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
After modifying dependencies, run:
flutter pub get
23. Source Control with VS Code
VS Code provides built-in Source Control functionality that can be used with Git repositories.
Basic Git Workflow
git init
git add .
git commit -m "Initial Flutter project"
git branch
git status
Developers can also connect their Flutter projects to platforms such as GitHub for source-code management and collaboration.
24. Useful VS Code Shortcuts for Flutter Development
| Shortcut |
Purpose |
| Ctrl + Shift + P |
Open Command Palette |
| Ctrl + P |
Quickly open a file |
| Ctrl + Shift + F |
Search across project |
| Ctrl + S |
Save file |
| Ctrl + . |
Quick fixes and code assists |
| F5 |
Start debugging |
| Ctrl + ` |
Open integrated terminal |
25. Common Problems and Troubleshooting
Problem 1: Flutter Command Not Found
'flutter' is not recognized as an internal or external command
Possible Solution:
- Verify that Flutter SDK is installed.
- Check the Flutter SDK location.
- Make sure the Flutter
bin directory is in PATH.
- Restart VS Code.
- Open a new terminal.
- Run
flutter doctor again.
Problem 2: No Devices Available
If VS Code displays No Devices, Flutter has not detected an available target device.
Possible Solutions:
- Start an Android emulator.
- Connect a physical Android device.
- Enable USB debugging on the Android device.
- Run
flutter devices.
- Check that the required platform tools are installed.
Problem 3: Flutter Extension Not Working
Possible Solutions:
- Check that the Flutter extension is installed.
- Check that the Dart extension is installed.
- Restart VS Code.
- Run Flutter Doctor.
- Open the correct Flutter project root.
- Make sure the project contains
pubspec.yaml.
Problem 4: Dependencies Are Not Available
If a package is added to pubspec.yaml but is not recognized, run:
flutter pub get
Then restart or reload the VS Code window if necessary.
26. Practical Example: Create a Simple Flutter App
Step 1: Create Project
flutter create my_flutter_app
Step 2: Open the Project
cd my_flutter_app
code .
Step 3: Open main.dart
Open:
lib/main.dart
Step 4: Replace the Code
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'VS Code Flutter Demo',
home: Scaffold(
appBar: AppBar(
title: const Text('VS Code Flutter Demo'),
),
body: const Center(
child: Text(
'Flutter is ready!',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
),
);
}
}
Step 5: Run the Application
flutter run
Alternatively, select a target device in VS Code and press F5.
27. Recommended VS Code Workflow for Flutter
- Open VS Code.
- Open the Flutter project.
- Check the Flutter and Dart extensions.
- Check the selected device.
- Open
lib/main.dart.
- Write or modify Flutter code.
- Save the file.
- Use hot reload for quick UI changes.
- Use breakpoints when debugging logic.
- Use DevTools when inspecting layout or performance.
- Run
flutter analyze to check code issues.
- Run tests using
flutter test.
- Commit changes using Git.
28. VS Code Flutter Setup Checklist
- VS Code installed
- Git installed
- Flutter SDK installed
- Flutter SDK added to PATH
- Flutter extension installed
- Dart extension available
flutter doctor executed successfully
- Flutter project created
pubspec.yaml detected
- Target device configured
- Flutter application successfully launched
- Hot reload tested
- Debugging tested
- DevTools tested
29. Practice Exercise
Create a Flutter application called student_profile using VS Code.
Requirements
- Create a new Flutter project.
- Open
lib/main.dart.
- Create an AppBar titled Student Profile.
- Display a student's name.
- Display the student's course.
- Display the student's email.
- Add an ElevatedButton.
- Run the application on a selected device.
- Change the UI using hot reload.
- Set a breakpoint and test debugging.
Sample Code
import 'package:flutter/material.dart';
void main() {
runApp(const StudentProfileApp());
}
class StudentProfileApp extends StatelessWidget {
const StudentProfileApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Student Profile'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Manish Negi',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
const Text('Flutter Development'),
const SizedBox(height: 10),
const Text('[email protected]'),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
print('Button clicked');
},
child: const Text('View Profile'),
),
],
),
),
),
);
}
}
30. Interview Questions
Q1. What is VS Code?
VS Code is a lightweight source-code editor that can be extended with Flutter and Dart support for Flutter application development.
Q2. Which extension is required for Flutter development in VS Code?
The Flutter extension is required. Installing the Flutter extension also installs the Dart extension.
Q3. How can you create a Flutter project in VS Code?
Open the Command Palette, select Flutter: New Project, choose the Application template, select the parent folder, and provide a project name.
Q4. How do you verify Flutter installation?
Run:
flutter doctor
Q5. What is hot reload?
Hot reload quickly applies many code and UI changes to a running Flutter application while generally preserving its current state.
Q6. What is hot restart?
Hot restart restarts the Flutter application and resets its current application state.
Q7. What is Flutter DevTools?
Flutter DevTools is a collection of debugging, inspection, and performance-analysis tools for Flutter and Dart applications.
Q8. What should you do if VS Code shows "No Devices"?
Connect or start a supported target device, then check the available devices using flutter devices.
31. Key Points to Remember
- VS Code is a popular editor for Flutter development.
- The Flutter extension provides Flutter-specific development features.
- The Flutter extension also installs Dart support.
- The Flutter SDK must be correctly installed and available to the development environment.
- The Flutter SDK's
bin directory can be added to PATH.
flutter doctor is useful for checking the development environment.
Flutter: New Project can be used to create a project directly from VS Code.
F5 starts a debugging session.
- Hot reload speeds up the Flutter development cycle.
- DevTools can help inspect and debug Flutter applications.
- The project root should contain
pubspec.yaml.
- A target device is required to run the application.
32. Learning Resources
Flutter Training: https://www.justacademy.co/course-detail/flutter-training
Course Demo Registration: https://www.justacademy.co/register-for-course-demo
Official Flutter VS Code Documentation: Flutter and VS Code
Install Flutter with VS Code: Flutter Installation Using VS Code
Create a New Flutter App: Flutter Create New App
Conclusion
Setting up VS Code for Flutter involves installing VS Code, configuring the Flutter SDK, installing the Flutter extension, verifying the Dart and Flutter environment, creating a Flutter project, selecting a target device, and testing the application. Once the setup is complete, VS Code provides an efficient environment for writing Dart code, building Flutter interfaces, debugging applications, using hot reload, and working with Flutter DevTools.